local files = {
	"UnitFlagManager_BuilderCharges.lua",
	"UnitFlagManager_BarbarianClansMode.lua",
	"UnitFlagManager.lua",
}

for _, file in ipairs(files) do
    include(file);
    if Initialize then
        break;
    end
end

local NATSUMI_WITCH_PENDING_KEY = 'NATSUMI_WITCH_COPY_PENDING';
function Natsumi_OnUnitFlagClick (playerId, unitId)
	OnUnitFlagClick(playerId, unitId);
	local localPlayerId = Game.GetLocalPlayer();
	local localPlayer = Players[localPlayerId];
	local pendingUnitId = localPlayer:GetProperty(NATSUMI_WITCH_PENDING_KEY);
	if pendingUnitId ~= nil then
		local greatPersonIndividualId = nil;
		local copyingUnit = UnitManager.GetUnit(playerId, unitId);
		if copyingUnit ~= nil then
			if copyingUnit:GetGreatPerson():IsGreatPerson() then
				greatPersonIndividualId = copyingUnit:GetGreatPerson():GetIndividual();
			end
		end
		ExposedMembers.GameEvents.HD_Natsumi_WitchCopySwitch.Call(playerId, unitId, localPlayerId, pendingUnitId, greatPersonIndividualId);
	end
end
SetInteractivity_Base = UnitFlag.SetInteractivity;
UnitFlag.SetInteractivity = function (self)
	SetInteractivity_Base(self);
	self.m_Instance.NormalButton:RegisterCallback(Mouse.eLClick, Natsumi_OnUnitFlagClick);
end